package tv.geir.slackspace.communication;

import java.io.Serializable;

import net.jini.id.Uuid;
import net.jini.id.UuidFactory;

public class Request implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Code requestType;
	private Uuid id;
	private Serializable data;
	private long leaseTime;
	
	

	/**
	 * @param data
	 * @param requestType
	 * @param leaseTime
	 */
	public Request(Serializable data, Request.Code requestType,  long leaseTime) {

		this.requestType = requestType;
		this.data = data;
		this.leaseTime = leaseTime;
		
		id = UuidFactory.generate();
	}
	
	
	/**
	 * @param data
	 * @param requestType
	 */
	public Request(Serializable data,Request.Code requestType) {
		this( data, requestType, 0 );
	}
	
	public Uuid getUuid() {
		return id;
	}
	
	public Serializable getData() {
		return data;
	}
	public void setData(Serializable data) {
		this.data = data;
	}
	public Request.Code getRequestType() {
		return requestType;
	}
	public void setRequestType(Request.Code requestType) {
		this.requestType = requestType;
	}
	public long getLeaseTime() {
		return leaseTime;
	}
	public void setLeaseTime(long leaseTime) {
		this.leaseTime = leaseTime;
	}
	
	public enum Code implements Serializable{
		WRITE, TAKE, READ, READ_IF_EXISTS, TAKE_IF_EXISTS;
	}
}
